package com.scs.application.core.exception;
/**
 * @Description： 业务异常
 */
public class BusinessException extends RuntimeException {

    private String message;

    /**
    * 使用 String.format 对字符串进行格式化
    */
    public BusinessException(String message, Object... args) {
        this.message = String.format(message, args);
    }


    public BusinessException(String message, Throwable throwable) {

        super(message, throwable);
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }


    /**
    * @Description：抛出异常，该异常输出到文件及日志中
    */
    public static void throwError(String message, Object... args) throws BusinessException {
        throw new BusinessException(message,args);
    }
    /**
    * @Description：抛出异常，该异常输出到文件及日志中
    */
    public static void throwErrorIf(boolean ifTrue, String message, Object... args) throws BusinessException {
        if (ifTrue) throw new BusinessException(message,args);
    }

    /**
    * @Description：抛出异常，该异常仅做事务回滚用户提示，不输出到文件及日志中
    */
    public static void throwValidFail(String message, Object... args) throws ValidException {
        throw new ValidException(message,args);
    }

    /**
     * @Description：抛出异常，该异常输出到文件及日志中
     */
    public static void throwValidFailIf(boolean ifTrue, String message, Object... args) throws BusinessException {
        if (ifTrue) throw new ValidException(message,args);
    }
}
